package 数组题目.数组变换;

//翻转字符串里的单词
//https://leetcode.cn/problems/reverse-words-in-a-string/description/
class 翻转字符串里的单词 {
    public String reverseWords(String s) {
        String[] strings = s.split(" ");
        StringBuilder ans = new StringBuilder();
        for (int i = strings.length - 1; i >= 0; i--) {
            if ("".equals(strings[i])) continue;
            if (!ans.isEmpty()) ans.append(" ");
            ans.append(strings[i]);
        }
        return ans.toString();
    }

//    public static void main(String[] args) {
//        String s = "the sky is blue";
//        System.out.println(new ReverseWords().reverseWords(s));
//    }
}
